﻿<%@ page language="java" import="java.util.*,code.bean.*,code.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	User loginUser = (User)ParamUtils.getObjectAttribute(session, "loginUser", null);
	List categorys = (List)ParamUtils.getObjectAttribute(request, "categorys", null);
	Code code = (Code)ParamUtils.getObjectAttribute(request, "code", null);
	String cmd = ParamUtils.getAttribute(request, "cmd", "");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>代码管理</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <META http-equiv="content-Type" content="text/html;charset=UTF-8">
    
	<link href="css/s.css" rel="stylesheet" type="text/css" />
    <link href="css/comment_7.css" rel="stylesheet" type="text/css" />
	<link type="text/css" rel="stylesheet" href="Styles/SyntaxHighlighter.css"></link>
		
		<SCRIPT language="javascript" src="js/code.js"></SCRIPT>
		<SCRIPT language="javascript" src="js/http.js"></SCRIPT>
		<script language="javascript">
			function checkForm() {
				var myForm = document.articleForm;
				if(myForm.title.value==""){
					alert("标题不能空!");
					return false;
				}
				if(myForm.lang.value==""){
					alert("语言不能空!");
					return false;
				}
				if(myForm.content.value==""){
					alert("内容不能空!");
					return false;
				}
				if(myForm.categoryid.value=="-1"){
					alert("您必须选择已建立的标签!");
					return false;
				}
				return true;
			}
			function showAddSection(){
				if(document.all.categoryid.value == -1)
					document.getElementById("addSection").style.display = "block";
				else
					document.getElementById("addSection").style.display = "none";
			}
			function addCategory(){
				var cateName = document.articleForm.newCategName.value;
				if(cateName == ""){
					alert("新标签名不能为空！");
					return false;
				}
				else{
					var text = openhttp("servlet/ManageCategory","cmd=add&categoryName="+cateName);
					if(text == "" || text == "error")
						alert("创建失败");
					else if(text == "exist")
						alert("该标签已存在");
					else{
						document.getElementById("addSection").style.display = "none";
						document.all.categoryid.options[document.all.categoryid.options.length - 1] = new Option(cateName,text);
						document.all.categoryid.options[document.all.categoryid.options.length] = new Option("新建标签","-1");
						document.all.categoryid.options[document.all.categoryid.options.length - 2].selected = true;
					}
				}
			}
		</script>
  </head>
  
<body>

<div id="head">
	<div class="hd">
		<div class="l tac wl2" style="width:720px;padding:3px;">
		<table width="100%"><tr>
			<td><div style="padding-left:15px;"><a href="servlet/ShowIndex1"><img src="images/pcslogo.gif"/></a></div></td>
			<td class="ce" style="font-size:14px">
			&nbsp;<a href="servlet/ShowSpace?userid=<%=ParamUtils.getParameter(request, "userid", "")%>" class="ce">主页</a>&nbsp;┊
			&nbsp;<a href="servlet/ShowCode?userid=<%=ParamUtils.getParameter(request, "userid", "")%>&blogdate=<%=DateUtils.format(Calendar.getInstance().getTime())%>" class="ce">我的代码</a>&nbsp;┊
			&nbsp;<a href="servlet/ShowShare?userid=<%=ParamUtils.getParameter(request, "userid", "")%>" class="ce">我的收藏</a>&nbsp;┊
			&nbsp;<a href="servlet/ShowProfile?userid=<%=ParamUtils.getParameter(request, "userid", "")%>" class="ce">用户信息</a>&nbsp;┊
			&nbsp;<a href="servlet/ManageCode?userid=<%=ParamUtils.getParameter(request, "userid", "")%>&cmd=add" class="ce">发布代码</a>&nbsp;┊
			&nbsp;<a href="../CodeSharer/advSearch.jsp?userid=<%=ParamUtils.getParameter(request, "userid", "")%>" class="ce">搜索</a>
			
			<%
				if(session.getAttribute("loginUser") != null && ((User)(session.getAttribute("loginUser"))).getId().equals(ParamUtils.getParameter(request, "userid", "")))
			    { 
					out.println("&nbsp;┊&nbsp;<a href=\"servlet/CodeList?userid=" + ParamUtils.getParameter(request, "userid", "") + "\" class=\"ce"+"\">代码管理</a>");
				    out.println("&nbsp;┊&nbsp;<a href=\"servlet/ShareList?userid=" + ParamUtils.getParameter(request, "userid", "") + "\" class=\"ce"+"\">收藏管理</a>");
				    out.println("&nbsp;┊&nbsp;<a href=\"servlet/DoLogout" + "\" class=\"ce"+"\">退出</a>");
				}
			%>
			</td>
		</tr></table>
		</div>
		<div align="right">
			<table>
			<tr>
			<td>
			    <div style="padding:4px;"></div>
				<form name="" action="servlet/SearchCodeByTitle?userid=<%=ParamUtils.getParameter(request, "userid", "")%>" method="post">
				<input type="text" name = "title1" value="" maxlength="15"/>
				<input type="submit" class="signinbtn1" value="搜标题"/>
				</form>
			</td>
			<td>
			&nbsp;&nbsp;&nbsp;&nbsp;
			<%if(session.getAttribute("loginUser") != null){ %>
			<a href="servlet/ShowSpace?userid=<%=
			((User)
			(session.getAttribute
			("loginUser"))).getId()
			%>" class="ce" style="font-size:16px">
			<%=((User)
			(session.getAttribute
			("loginUser"))).getNickName()%>
			</a>
			<%}%>
			</td>
			</tr>
			</table>
		</div>
		<div class="c"></div>
	</div>
</div>
<!--Head End-->

<div id="main">
	<div class="m1 wl2" style="width:230px;">
    	<div class="m1t"></div>
       <div style="padding:15px 0 0 15px;">
		
		    <div class="f13 ml20"><span style="font:bold 20px '黑体'; color:#D01E3B;">CodeSharer<br /></span> </div>
		    <div style="background:url(images/index_app.gif) repeat-x;width:190px;margin:20px auto 15px 7px;height:2px;"></div>

            <div id="text1div" class="f13 ml20"><img src="images/arrow_l.gif" align="absmiddle" />这里是帮助你管理你的代码，并与你的朋友、同事、同学一起分享代码的真实平台</div>
	     
			<div style="background:url(images/index_app.gif) repeat-x;width:190px;margin:20px auto 15px 7px;height:2px;"></div>
						
			<div id="text1div" class="f13 ml20"><img src="images/arrow_l.gif" align="absmiddle" />支持代码高亮显示</div>
			<div style="padding:2px;"></div>
			<div id="text1div" class="f13 ml20"><img src="images/arrow_l.gif" align="absmiddle" />支持代码版本控制</div>
			<div style="padding:2px;"></div>
			<div id="text1div" class="f13 ml20"><img src="images/arrow_l.gif" align="absmiddle" />支持代码分享、收藏、评论</div>
			<div style="padding:2px;"></div>
		</div>
    </div>
	
	<div class="m2 wr2" style="width:770px;">
	   <div id="r2s_2">
	        
			<div style="padding:3px;"></div>
	   
	   		<form name="articleForm" action="servlet/ManageCode?userid=<%=loginUser.getId()%>" method="post">
			<INPUT type="hidden" name="cmd" value="save">
			<INPUT type="hidden" name="id" value="<%=code != null ? code.getId() : ""%>">
			<div style="padding:10px;"></div>
			<TABLE>
		        <tr>
		          <td width="100%" height="18" align="left">
		          	<%
		          		if(cmd.equals("add")){
		          			out.println("贴代码");
		          		}
		          		else if(cmd.equals("view")){
		          			out.println("查看代码");
		          		}
		          		else if(cmd.equals("edit")){
		          			out.println("修改代码");
		          		}
		          	%>
		          	<%if(cmd.equals("view")) {%>
		          	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		          	<input type="button" class="signinbtn1" onclick="location.href='../servlet/ShareCode?codeid=<%=code.getId()%>&userid=<%=code.getUserid()%>'" value="收藏">
					<input type="button" class="signinbtn1" onclick="location.href='../servlet/ShowItems?codeid=<%=code.getId()%>&userid=<%=code.getUserid()%>'" value="历史版本">
					<%} %>
					<div style="padding:5px;"></div>
		          </td>
		        </tr>
				
				<tr>
				  <td height="19" align="left">标题:&nbsp;
		          	<%
		          		if(cmd.equals("add")){
		          			out.println("<input type=\"text\" name=\"title\" size=\"40\"> （最多50位！）");
		          		}
		          		else if(cmd.equals("view")){
		          			out.println("<input type=\"text\" name=\"title\" value=\""+code.getTitle()+"\" disabled>");
		          		}
		          		else if(cmd.equals("edit")){
		          			out.println("<input type=\"text\" name=\"title\" value=\""+code.getTitle()+"\" disabled>");
		          		}
		          	%>
		          	<div style="padding:5px;"></div>
		          </td>
		        </tr>
				
		        <tr>
				  <td height="19" align="left">语言:&nbsp;
				  <%
			          		if(cmd.equals("add")){
		          				out.println("<select name=\"lang\">");
			          			out.println("<option value=\"CPP\">C++</option>");
			          			out.println("<option value=\"Java\">Java</option>");
			          			out.println("<option value=\"Csharp\">C#</option>");
			          			out.println("<option value=\"PHP\">PHP</option>");
			          			out.println("<option value=\"JScript\">JScript</option>");
			          			out.println("<option value=\"Vb\">Vb</option>");
			          			out.println("<option value=\"Sql\">Sql</option>");
			          			out.println("<option value=\"Delphi\">Delphi</option>");
			          			out.println("<option value=\"Xml\">Xml</option>");
			          			out.println("<option value=\"Python\">Python</option>");
			          			out.println("<option value=\"Ruby\">Ruby</option>");
			          			out.println("<option value=\"Css\">Css</option>");
		          				out.println("</select>");
			          		}
			          		else if(cmd.equals("view"))
			          		{
			          		    out.println("<select name=\"lang\" disabled>");
			          		    out.println("<option value=\"" + code.getLanguage() + "\">"+ code.getLanguage() +"</option>");
		          				out.println("</select>");
			          		}
			          		else if(cmd.equals("edit")){
		          				out.println("<select name=\"lang\" disabled>");
		          				out.println("<option value=\"" + code.getLanguage() + "\">"+ code.getLanguage() +"</option>");
		          				out.println("</select>");
		          			}		
			       %>
			       <div style="padding:5px;"></div>
		          </td>
		        </tr>
		        <tr>
		          <td height="19" align="left">
		          	<table>
		          		<tr>
		          			<td>标签:&nbsp;
		          			
			          	<%
			          		if(cmd.equals("add")){
		          				out.println("<select name=\"categoryid\" onchange=\"showAddSection()\">");
		        				for(int i = 0;i < categorys.size(); i++){
		        					Category category = (Category)categorys.get(i);
			          				out.println("<option value=\""+category.getId()+"\">"+category.getCategoryName()+"</option>");
			          			}
			          			out.println("<option value=\"-1\">新建</option>");
		          				out.println("</select>");
			          		}
			          		else if(cmd.equals("view")){
		          				out.println("<select name=\"categoryid\" disabled>");
		        				for(int i = 0;i < categorys.size(); i++){
		        					Category category = (Category)categorys.get(i);
		        					if(code.getCategoryid().equals(category.getId())){
			          					out.println("<option value=\""+category.getId()+"\" selected>"+category.getCategoryName()+"</option>");
		        					}
		        					else{
			          					out.println("<option value=\""+category.getId()+"\">"+category.getCategoryName()+"</option>");
		        					}
			          			}
		          				out.println("</select>");
			          		}
			          		else if(cmd.equals("edit")){
		          				out.println("<select name=\"categoryid\" onchange=\"showAddSection()\">");
		        				for(int i = 0;i < categorys.size(); i++){
		        					Category category = (Category)categorys.get(i);
		        					if(code.getCategoryid().equals(category.getId())){
			          					out.println("<option value=\""+category.getId()+"\" selected>"+category.getCategoryName()+"</option>");
		        					}
		        					else{
			          					out.println("<option value=\""+category.getId()+"\">"+category.getCategoryName()+"</option>");
		        					}
			          			}
			          			out.println("<option value=\"-1\">新建标签</option>");
		          				out.println("</select>");
			          		}
			          	%>
			          	<div style="padding:5px;"></div>
				          	</td>
				          	<td>
		          				<span id="addSection" style="display: none;">
		          				<INPUT type="text" name="newCategName" size="20">
		          				<INPUT type="button" class="inputbtn" value="新建" onClick="addCategory()">
		          				</span>
		          				<SCRIPT language="javascript">
		          					if(document.all.categoryid.disabled != true && document.all.categoryid.options.length <= 1)
		          						document.getElementById("addSection").style.display = "block";
		          				</SCRIPT>
		          				<div style="padding:5px;"></div>
				          	</td>
			          		</tr>
			
			          	</table>
		          </td>
		        </tr>
		        
		            <%
		          		if(cmd.equals("view")||cmd.equals("edit")){%>
		          		<tr>
				  		<td height="19" align="left">发表时间:&nbsp;
				  		<%out.println("<input type=\"text\" name=\"title\" value=\""+code.getPublishTime()+"\" disabled>");%>
				  		<div style="padding:5px;"></div>
				  		</td>
		        		</tr>
		          		<%}
		          	%>
		        <tr>
		        
		          <td height="19" align="left">内容:
		          <div style="padding:3px;"></div>
		          </td>
		        </tr>
				
		        <tr>
		          <td align="left" width="100%">
		          	<%
		          		if(cmd.equals("add")){
		          			out.println("<textarea name=\"content\" cols=\"100\" rows=\"20\"></textarea>");
		          		}
		          		else if(cmd.equals("view")){
		          			out.println("<textarea name=\"content\" class=\""+ code.getLanguage() + "\"cols=\"100\" rows=\"20\" readonly>"+code.getContent()+"</textarea>");
		          		}
		          		else if(cmd.equals("edit")){
		          			out.println("<textarea name=\"content\" cols=\"100\" rows=\"20\">"+code.getContent()+"</textarea>");
		          		}
		          	%>
		          	<div style="padding:3px;"></div>
		          </td>
		           <script class="javascript" src="Scripts/shCore.js"></script>
					<script class="javascript" src="Scripts/shBrushCSharp.js"></script>
					<script class="javascript" src="Scripts/shBrushPhp.js"></script>
					<script class="javascript" src="Scripts/shBrushJScript.js"></script>
					<script class="javascript" src="Scripts/shBrushJava.js"></script>
					<script class="javascript" src="Scripts/shBrushVb.js"></script>
					<script class="javascript" src="Scripts/shBrushSql.js"></script>
					<script class="javascript" src="Scripts/shBrushXml.js"></script>
					<script class="javascript" src="Scripts/shBrushDelphi.js"></script>
					<script class="javascript" src="Scripts/shBrushPython.js"></script>
					<script class="javascript" src="Scripts/shBrushRuby.js"></script>
					<script class="javascript" src="Scripts/shBrushCss.js"></script>
					<script class="javascript" src="Scripts/shBrushCpp.js"></script>
					<script class="javascript">
					dp.SyntaxHighlighter.HighlightAll('content');
					</script>
					
				  </tr>
				  <%if(cmd.equals("edit")) {%>
				    <tr>
		          		<td height="19" align="left">更新说明:
		          		<div style="padding:3px;"></div>
		          		</td>
		        	</tr>
				  	<tr>
						<td style="font-size: 16px;">
							<input type="text" name="caption" size="100">
						</td>
					</tr>
					
				  	<%} %>
				  <%if(cmd.equals("view")) {%>
				  	<tr>
						<td style="font-size: 12px;">
							<%=code.getPublishTime().substring(0,16)%>&nbsp;&nbsp;
							|&nbsp;&nbsp;<A href="javascript:openRemarkSection(<%=code.getId()%>,<%=code.getUserid()%>)">评论（<span id="remarkNum<%=code.getId()%>"><%=code.getRemarkNum()%></span>）</A>
							<div id="remarkSection<%=code.getId()%>" style="display: none;">评论区</div>
						</td>
					</tr>
					
				  	<%} %>
				<tr>
		          <td height="18" align="center">
		           
		            <div style="padding:5px;"></div>
		          	<%
		          		if(!cmd.equals("view")){
		          	%>
			          <INPUT type="button" value="保存" class="rb1" onClick="if(checkForm()) document.articleForm.submit();"  onMouseOver="this.className='rb2';" onMouseOut="this.className='rb1';" >
			        <%
			        	}
			        %>
			          &nbsp;&nbsp;<INPUT type="button" class="rb1" value="返回" onClick="history.back(1)" onMouseOver="this.className='rb2';" onMouseOut="this.className='rb1';">
		          <div style="padding:3px;"></div>
		          </td>
		        </tr>
				
					
			</TABLE>
		</form>
		<div style="padding:10px;"></div>
	   
	   </div>
	</div>
</div>

<div id="b">
	<div class="b1"><a href="#" class="c6" target="_blank">关于我们</a><span>┊</span><a href="/s/contact.html" class="c6" target="_blank">联系方式</a><span>┊</span><a href="/t/feedback.html" class="c6" target="_blank">意见反馈</a><span>┊</span><a href="/s/help.html" class="c6" target="_blank">帮助中心</a>　 &nbsp;<a class=c6 href=http://www.miibeian.gov.cn target=_blank>NENU</a> <img src="images/gs.gif" width="15" align="absmiddle" />&nbsp;<img src="images/jc.gif" width="17" align="absmiddle" /></div>

</div>


</body>
</html>